<?php
class WebUser extends CWebUser {
	private $_model = null;

	public function init()
	{
		$conf = Yii::app()->session->cookieParams;
		$this->identityCookie = array(
				'path' => $conf['path'],
				'domain' => $conf['domain'],
		);
		parent::init();
	}
	
	function getRole() {
		if($user = $this->getModel()){
			// в таблице User есть поле role
			return $user->userType->role;
		}
	}

	private function getModel(){
		if (!$this->isGuest && $this->_model === null){
			$this->_model = User::model()->findByPk($this->id)->with('userType', array('select' => 'role'));
		}
		return $this->_model;
	}
	
	public function login($destroySession = true)
	{
	
		if ($this->allowAutoLogin && isset($this->identityCookie['domain']))
		{
	
			$cookies = Yii::app()->getRequest()->getCookies();
	
			if (null !== ($cookie = $cookies[$this->getStateKeyPrefix()]))
			{
				$originalCookie = new CHttpCookie($cookie->name, $cookie->value);
				$cookie->domain = $this->identityCookie['domain'];
				$cookies->remove($this->getStateKeyPrefix());
				$cookies->add($originalCookie->name, $originalCookie);
			}
	
		}
	
		parent::login($destroySession);
	
	}
}